package com.cqvie.dao;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.cqvie.model.TeacherMaster;

@Transactional
@Repository("masterTeacherDao")
public class MasterTeacherDao {
	@Resource
	protected SessionFactory sessionFactory;

	// 通过ID来查询班主任信息
	@SuppressWarnings("unchecked")
	public List<TeacherMaster> selectByID(int id) {
		List<TeacherMaster> tms = new ArrayList<TeacherMaster>();
		Session session = sessionFactory.getCurrentSession();
		String hql = "from TeacherMaster tmas where tmas.teacherMID=?";
		Query query = session.createQuery(hql);
		query.setInteger(0, id);
		tms = query.list();
		if(tms.size()>=1){
			return tms;
		}else
			return null;
	}

	public TeacherMaster GetTeacherMaster(int TMid){
		Session session=sessionFactory.getCurrentSession();
		TeacherMaster TMaster=(TeacherMaster)session.get(TeacherMaster.class, TMid);
		return TMaster;
	}
	
	//添加班主任信息
	public void addTeacher(TeacherMaster mt) {
		Session session=sessionFactory.getCurrentSession();
		session.save(mt);
		}
}
